package cn.ronghuanet.base.controller;

import cn.ronghuanet.base.service.IFastdfsService;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.FastdfsUtil;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/fastdfs")
public class FastdfsController {

    @Autowired
    private IFastdfsService fastdfsService;

    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws Exception{
        // 获取的是这个文件对象的参数名
        // String name = file.getName();
        String fastDfsUrl = fastdfsService.upload(file);
        return AjaxResult.success(fastDfsUrl);
    }

    @DeleteMapping
    public AjaxResult delete(String path){
        fastdfsService.delete(path);
        return AjaxResult.success();
    }
}
